} else if (todayLevel==0.0){ break;
  private void createAllocations(int todayBucket, int endBucket,                                 Inventory inv, LogisticsInventoryPG thePG) {    int currentBucket = todayBucket;    double qty = 0;    double todayLevel, todayRefill;    Task withdraw;    // DEBUG    //   String myOrgName = inventoryPlugin.getMyOrganization().getItemIdentificationPG().getItemIdentification();    //   String myItemId = inv.getItemIdentificationPG().getItemIdentification();    //if ((myOrgName.indexOf("592") >= 0) && (myItemId.indexOf("Level2Amm") >= 0)) {    //	      System.out.println("### createAlloc : Assesing allocations RIGHT ORG NAME COMBO - " + myOrgName + " - " + myItemId);    //}    // loop through the buckets in the inventory    while (currentBucket <= endBucket) {      todayRefill = findCommittedRefill(currentBucket, thePG, true);      todayLevel = thePG.getLevel(currentBucket - 1) + todayRefill;            /***       **      if((inventoryPlugin.getOrgName().indexOf("47-FSB") != -1) &&         (thePG.getItemName().indexOf("9140002865294") != -1)) {        logger.error("createAllocations - bucket is "+getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket))+                     ", committed refill "+todayRefill+" and today's inventory level "+todayLevel);      }      **/      // First try to fill any previous deficits      Iterator tpIt = trailingPointers.iterator();      while (tpIt.hasNext()) {        TaskDeficit td = (TaskDeficit) tpIt.next();        withdraw = td.getTask();        qty = td.getRemainingQty();	// DEBUG Task deficits	//if ((myOrgName.indexOf("592-ORDCO") >= 0) && (myItemId.indexOf("Level2Am") >= 0)) {	//    System.out.println("### createAlloc : trying to fill a PREVIOUS deficit for task:|" + withdraw.getUID() + "| : todaylevel|" + todayLevel + "| and qty is |" + qty + "| and the date is " +  getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket)));	//}        // check the level        if (todayLevel >= qty) {          // Can completely fill known deficit          /***           **          if((inventoryPlugin.getOrgName().indexOf("47-FSB") != -1) &&             (thePG.getItemName().indexOf("9140002865294") != -1)) {            logger.error("calculateAllocations - filling deficit on day "+                         getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket))+                         " and the remaining qty is "+qty+" and new inventory level is "+todayLevel+" for task "+                         withdraw.getUID() + " task request qty " + getTaskUtils().getDailyQuantity(withdraw));                         }                  **/          fillDeficit(td,currentBucket,inv,thePG);          todayLevel = todayLevel - qty;        } else if (todayLevel==0.0){          break;        } else {          //this withdraw has previously had a deficit we cannot fill the deficit entirely during this bucket`          //  leave the TaskDeficit in the same place on the queue -- it still needs to be filled with its old priority                    /****           ***          if((inventoryPlugin.getOrgName().indexOf("47-FSB") != -1) &&             (thePG.getItemName().indexOf("9140002865294") != -1)) {            logger.error("calculateAllocations - adding phase on day "+                         getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket))+                         " and td.remaining qty is " + qty + " today level is " + todayLevel + " setting today level to 0. This is for task " + withdraw.getUID() +  " task request daily quantity " + getTaskUtils().getDailyQuantity(withdraw ));                         }            **/          td.addPhase(todayLevel, currentBucket);          todayLevel = 0.0;          break; // nothing more to allocate        }      }      // remove any trailing pointers we filled      trailingPointers.removeAll(trailingPointersRemove);      trailingPointersRemove.clear();      // Fill any counted tasks with remaining inventory (if any)      Collection wdTasks = thePG.getActualDemandTasks(currentBucket);      Iterator wdIter = wdTasks.iterator();      while(wdIter.hasNext()) {        withdraw = (Task)wdIter.next();        qty = taskQtyInBucket(withdraw, currentBucket, thePG);        // check the level        if ((todayLevel - qty)>-.00000005) {          // enough inventory to fill task completely          //  NOTE: we have had a case where todayLevel= 12.999999999999995          //   and quantity = 12.999999999999998          fulfillTask(withdraw,currentBucket,inv,thePG);          todayLevel = Math.max(0.0, todayLevel - qty);          /***           **          if((inventoryPlugin.getOrgName().indexOf("47-FSB") != -1) &&             (thePG.getItemName().indexOf("9140002865294") != -1)) {            logger.error("calculateAllocations - fulfill task on day "+                         getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket))+                         " demand is "+qty+" and new inventory level is "+todayLevel+" for task "+                         withdraw.getUID() + " task qty " + getTaskUtils().getDailyQuantity(withdraw));          }          **          */        } else {          // can't fill this task totally -- create deficit on this task          // if it already has a pe - rescind it          PlanElement pe = withdraw.getPlanElement();          if (pe != null) inventoryPlugin.publishRemove(pe);          TaskDeficit td = getTaskDeficit(withdraw,currentBucket,thePG);          td.addPhase(todayLevel, currentBucket);	  // DEBUG Task deficits	  //if ((myOrgName.indexOf("592-ORDCO") >= 0) && (myItemId.indexOf("Level2Amm") >= 0)) {	  //    System.out.println("### createAlloc : adding a phase to a task deficit/deficit added to TRAILING POINTERS for task:|" 	  //+ td.getTask().getUID() +"|  todaylevel|" + todayLevel + 	  // "| and qty is |" + qty + "| and the date is " +  	  //getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket)));	  //}          /***           **          if((inventoryPlugin.getOrgName().indexOf("47-FSB") != -1) &&             (thePG.getItemName().indexOf("9140002865294") != -1)) {            logger.error("calculateAllocations - deficit for task on day "+                         getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket))+                         " demand is "+qty+" and new inventory level is 0.0 and provided "+todayLevel+" to "+                         withdraw.getUID()+ " task qty " + getTaskUtils().getDailyQuantity(withdraw) + " TD: remainingQty " + td.getRemainingQty() + " backlog " + td.backlog);              if(td.lastPhase != null) {                logger.error("And Last Phase is = " + td.lastPhase.toString(thePG));              }          }                    ***          **/                    trailingPointers.add(td);          // this task depletes the inventory level          todayLevel = 0.0;        }      }      //when we are done going through all the tasks for the day set the level      thePG.setLevel(currentBucket, todayLevel);      currentBucket = currentBucket + 1;    }    // DEBUG inventory levels    //if ((myOrgName.indexOf("592-ORDCO") >= 0) && (myItemId.indexOf("Level2Amm") >= 0)) {	//  for(currentBucket = 0; currentBucket<80; currentBucket++){    //if (thePG.convertBucketToTime(currentBucket) >= 1128643200000L) {	//System.out.println("###-" + myOrgName +     //"-createAlloc Inventory Level = "+	//thePG.getLevel(currentBucket)+ " on ("+ currentBucket +") " +	//getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket)));	//	}    // }	//}    //when we are finished, if we have things left in trailingPointers, fail them    Iterator tpIt = trailingPointers.iterator();    while (tpIt.hasNext()) {      TaskDeficit td = (TaskDeficit) tpIt.next();      createPhasedAllocationResult(td, inv, thePG, false);    }  }