Example 15 : Searching for delivery options meeting a range of delivery dates
This will identify all the days that a delivery can be made between 1st and 28th February (inclusive). It will choose the cheapest that can deliver on each day, and then order the results by the delivery slot. This would be an ideal candidate for providing data to populate a calendar of some sorts.
Note the inclusion of the maxAnalysisDayCount filter property. This is set to just above the range of dates we expect to look over. It is provided as a safety mechanism for catching erroneous dates (such as three years in the future). Needless to say, that kind of calculation would take a considerably long time!
package com.metapack.dm.test; import com.metapack.deliverymanager.client.AllocationFilter; import com.metapack.deliverymanager.client.Consignment; import com.metapack.deliverymanager.client.DateRange; import com.metapack.deliverymanager.client.DeliveryOption; import com.metapack.deliverymanager.client.webservices.AllocationService; public class Example15 extends ExampleBase { public void run() throws Exception { AllocationService service = createAllocationService(); Consignment consignment = createDefaultConsignment( "EXAMPLE-15" , 1 ); DateRange acceptableDeliverySlot = new DateRange( createDate( "2009-02-01T00:00:00" ) , createDate( "2009-02-28T23:59:59" ) ); AllocationFilter filter = new AllocationFilter(); filter.setFirstCollectionOnly( false ); filter.setMaxAnalysisDayCount( 30 ); filter.setAcceptableDeliverySlots( new DateRange[] { acceptableDeliverySlot } ); filter.setPreFilterSortOrder1( ExampleBase.SORT_COST_CHEAPEST ); filter.setFilterGroup1( ExampleBase.FILTER_GROUP_DELIVERY_DAY ); filter.setSortOrder1( ExampleBase.SORT_EARLIEST_DELIVERY_ASCENDING ); DeliveryOption[] options = service.findDeliveryOptions( consignment , filter ); for( DeliveryOption option : options ) { System.out.println( "Service " + option.getCarrierServiceCode() + " can deliver it and it will cost " + option.getCost() + " collection between " + formatDateRangeNice( option.getCollectionWindow() ) + " and delivery between " + formatDateRangeNice( option.getDeliveryWindow() ) ); } } }

