thePG.setLevel(refillBucket, 0);
thePG.setLevel(refillBucket, invLevel);
  public void calculateRefills(ArrayList touchedInventories, InventoryPolicy policy) {    int orderShipTime = policy.getOrderShipTime();    int maxLeadTime = policy.getSupplierAdvanceNoticeTime() + orderShipTime;        //Should we push now to the end of today? For now we WILL NOT.    //long today = getTimeUtils().    //  pushToEndOfDay(inventoryPlugin.getCurrentTimeMillis());    long today = inventoryPlugin.getCurrentTimeMillis();    //start time (k) is today plus OST.    long start = getTimeUtils().addNDays(today, orderShipTime);        Iterator tiIter = touchedInventories.iterator();    while (tiIter.hasNext()) {      Inventory anInventory = (Inventory) tiIter.next();      LogisticsInventoryPG thePG = (LogisticsInventoryPG)anInventory.        searchForPropertyGroup(LogisticsInventoryPG.class);      //clear the refills      thePG.clearRefillTasks(new Date(start));      int startBucket = thePG.convertTimeToBucket(start);      // refill time is start + 1 bucket (k+1)      int refillBucket = startBucket + 1;       // max lead day is today + maxLeadTime      int maxLeadBucket = thePG.convertTimeToBucket(getTimeUtils().                                             addNDays(today, maxLeadTime));      //  create the refills      while (refillBucket <= maxLeadBucket) {         double invLevel = thePG.getLevel(startBucket) -           thePG.getActualDemand(refillBucket);        if (thePG.getCriticalLevel(refillBucket) < invLevel) {          thePG.setLevel(refillBucket, 0);        } else {          int reorderPeriodEndBucket = refillBucket + (int)thePG.getReorderPeriod();          double refillQty = generateRefill(invLevel, refillBucket,                                             reorderPeriodEndBucket, thePG);          // make a task for this refill and publish it to glue plugin          // and apply it to the LogisticsInventoryBG          createRefillTask(refillQty, thePG.convertBucketToTime(refillBucket),                            anInventory, thePG, today);          thePG.setLevel(refillBucket, (invLevel + refillQty));        }        //reset the buckets        startBucket = refillBucket;        refillBucket = startBucket + 1;      }        } // done going through inventories  }