Example 75 : Find delivery options with a filter
This example shows you how to find delivery options with an allocation filter.
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 Example75 extends ExampleBase { public void run() throws Exception { AllocationService service = createAllocationService(); Consignment consignment = createDefaultConsignment( "EXAMPLE-75" , 1 ); DateRange acceptableDeliverySlot = new DateRange( createDate( "2009-02-19T00:00:00" ) , createDate( "2009-02-19T23:59:59" ) ); AllocationFilter filter = new AllocationFilter(); filter.setFirstCollectionOnly( true ); filter.setAcceptableDeliverySlots( new DateRange[] { acceptableDeliverySlot } ); filter.setPreFilterSortOrder1( ExampleBase.SORT_EARLIEST_COLLECTION_ASCENDING ); filter.setFilterGroup1( ExampleBase.FILTER_GROUP_SERVICE ); filter.setSortOrder1( ExampleBase.SORT_EARLIEST_COLLECTION_DAY_ASCENDING ); filter.setSortOrder2( ExampleBase.SORT_COST_CHEAPEST ); DeliveryOption[] options = service.findDeliveryOptions( consignment , filter ); for( DeliveryOption option : options ) { System.out.println( "Service " + option.getCarrierServiceCode() + " can deliver it and it will cost " + option.getShippingCost() + " collection between " + formatDateRangeNice( option.getCollectionWindow() ) + " and delivery between " + formatDateRangeNice( option.getDeliveryWindow() ) ); } } public static void main(String[] args) { Example75 instance = new Example75(); try { instance.run(); } catch( Exception e ) { e.printStackTrace(); } } }

