logger.debug("AA Failing task: " + getTaskUtils().taskDesc(withdraw) + " on day " + new Date (thePG.convertBucketToTime(currentBucket)) + " today level is " + todayLevel + " quantity is " + qty);
  private void createAllocations(int todayBucket, int endBucket,                                         Inventory inv, LogisticsInventoryPG thePG) {    int currentBucket = todayBucket;    double qty = 0;    double runningQty = 0;    double todayLevel, yesterdayLevel, todayRefill, testLevel, testQty;    AllocationResult result = null;    Task withdraw;    // loop through the buckets in the inventory    while (currentBucket <= endBucket) {      todayRefill = findCommittedRefill(currentBucket, thePG);      todayLevel = thePG.getLevel(currentBucket - 1) + todayRefill;      // 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();        // check the level        if (todayLevel >= qty) {	    // Can completely fill known deficit	    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	    td.addPhase(todayLevel, currentBucket);	    todayLevel = 0.0;	    break; // nothing more to allocate        }      }      // remove any trailing pointers we filled      trailingPointers.removeAll(trailingPointersRemove);      // 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) {	      // enough inventory to fill task completely	      fulfillTask(withdraw,currentBucket,inv,thePG); 	      todayLevel = todayLevel - qty;	  } 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);              logger.debug("AA Failing task: " + getTaskUtils().taskDesc(withdraw) + " on day " +                                  new Date (thePG.convertBucketToTime(currentBucket)) +                                  " today level is " + todayLevel + " quantity is " + qty);	      td.addPhase(todayLevel, currentBucket);	      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;    }    //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, currentBucket, inv, thePG, false);          }  }