startBucket = thePG.convertTimeToBucket(startDay, false) + inventoryPlugin.getOrderShipTime();
startDay = now + ((inventoryPlugin.getOrderShipTime() * thePG.getBucketMillis())); startBucket = thePG.convertTimeToBucket(startDay, true);
  protected void calculateLevelSixProjections(Collection touchedInventories,                                             int daysOnHand, long endOfLevelSix, 					    ComparatorModule myComparator) {    ArrayList refillProjections = new ArrayList();    ArrayList oldProjections = new ArrayList();    Iterator tiIter = touchedInventories.iterator();    while (tiIter.hasNext()) {      // clear out the old and new projections for the last Inventory      refillProjections.clear();      oldProjections.clear();      Inventory anInventory = (Inventory) tiIter.next();      LogisticsInventoryPG thePG = (LogisticsInventoryPG)anInventory.        searchForPropertyGroup(LogisticsInventoryPG.class);                  //start time is the start time of the inventorybg      long startDay = thePG.getStartTime();      if(startDay < inventoryPlugin.getRefillStartTime()) {        startDay = inventoryPlugin.getRefillStartTime();      }      int startBucket = thePG.convertTimeToBucket(startDay, false);      long now = inventoryPlugin.currentTimeMillis();      if (now > startDay) {	  startDay = now;	  // OLD - Now that were keeping the old projected demand in the past we 	  // only plan from now on.	  //	  startBucket = startBucket + inventoryPlugin.getOrderShipTime();	  startBucket = thePG.convertTimeToBucket(startDay, false) + inventoryPlugin.getOrderShipTime();      }      // clear all of the projections      //oldProjections.addAll(thePG.clearRefillProjectionTasks(startDay));      long cutoffTime = now + ((inventoryPlugin.getOrderShipTime() + 1) * thePG.getBucketMillis());      oldProjections.addAll(thePG.clearRefillProjectionTasks(cutoffTime));      //grab the overlapping tasks and change their end time      ArrayList projectionsToCut = (ArrayList) thePG.getOverlappingRefillProjections();      Iterator toCut = projectionsToCut.iterator();      while(toCut.hasNext()) {	  Task taskToCut = (Task) toCut.next();	  if (taskToCut != null) {	      Preference new_end = createRefillTimePreference(cutoffTime, 							      inventoryPlugin.getOPlanArrivalInTheaterTime(),							      AspectType.END_TIME, thePG);	      ((NewTask)taskToCut).setPreference(new_end);	      inventoryPlugin.publishChange(taskToCut);	      thePG.updateRefillProjection(taskToCut);	  }      }	            int currentBucket = startBucket;//       int customerDemandBucket = thePG.convertTimeToBucket(getTimeUtils().//                                                            addNDays(startDay, daysOnHand), true);      int customerDemandBucket = thePG.convertTimeToBucket(startDay, false) + daysOnHand;       double projDemand = 0;      double nextProjDemand = 0;      int endOfLevelSixBucket = thePG.convertTimeToBucket(endOfLevelSix, false);      thePG.setEndOfLevelSixBucket(endOfLevelSixBucket);            //get the initial demand for the customer for startBucket + daysOnHand      //Is there a better way to do this to avoid the duplication?      projDemand = thePG.getProjectedDemand(customerDemandBucket);            //move forward a bucket      currentBucket = currentBucket + 1;      customerDemandBucket = customerDemandBucket + 1;            //Begin looping through currentBucket forward until you hit the end of      // the level six boundary      //possible boundary issue... is it '<' or '<=' ??      while (currentBucket < endOfLevelSixBucket) {        nextProjDemand = thePG.getProjectedDemand(customerDemandBucket);        if (projDemand != nextProjDemand) {          //if there's a change in the demand, create a refill projection 	  //BUT only if demand is non-zero 	  if (projDemand > 0.0) {	    Task refill = createProjectionRefill(thePG.convertBucketToTime(startBucket), 						 thePG.convertBucketToTime(currentBucket),						 projDemand, thePG);            if (startBucket >= currentBucket) {              logger.error("Invalid task : "+getTaskUtils().taskDesc(refill)+", startDay: "+                           getTimeUtils().dateString(startDay)+", startBucket: "+startBucket+                           ", currentBucket: "+currentBucket);            } else {              refillProjections.add(refill);            }	  }          //then reset the start bucket and the new demand           startBucket = currentBucket;          projDemand = nextProjDemand;        }        //in either case bump current and customer forward a bucket.        currentBucket = currentBucket + 1;        customerDemandBucket = customerDemandBucket + 1;      }      // when we get to the end of the level six window create the last      // projection task (if there is one)      if (startBucket != currentBucket) {	// HERE LIES A BUG.  We should never generate zero demand projection tasks	// and never generate projection tasks that go beyond the end of the war	if (projDemand > 0.0) {	  Task lastRefill = createProjectionRefill(thePG.convertBucketToTime(startBucket),						   thePG.convertBucketToTime(currentBucket),						   projDemand, thePG);          if (startBucket >= currentBucket) {            logger.error("Invalid task : "+getTaskUtils().taskDesc(lastRefill)+", startDay: "+                         getTimeUtils().dateString(startDay)+", startBucket: "+startBucket+                         ", currentBucket: "+currentBucket);          } else {            refillProjections.add(lastRefill);          }        }      }      // send the new projections and the old projections to the Comparator      // the comparator will rescind the old and publish the new projections      myComparator.compareRefillProjections(refillProjections, oldProjections,                                             anInventory);           if (thePG.getIsLevel2()) {        setTargetForProjectionPeriod(thePG, 0, thePG.getInitialLevel());      }    }      }