Example 07 : Creating and allocating a consignment using a booking code

Printer-friendly version

 This will create a single consignment and allocate it to a carrier. It will respect the booking code. The example shows a booking code that will make the system choose the best service that can despatch on or after 15th February 2009.

I've also chosen to demonstrate creating and allocating multiple consignments.

 

package com.metapack.dm.test;
 
import com.metapack.deliverymanager.client.Consignment;
import com.metapack.deliverymanager.client.webservices.AllocationService;
 
public class Example7 extends ExampleBase {
 
	public void run() throws Exception {
		AllocationService service = createAllocationService();
		Consignment consignment1 = createDefaultConsignment( "EXAMPLE-7a" , 1 );
		Consignment consignment2 = createDefaultConsignment( "EXAMPLE-7b" , 3 );
 
		String bookingCode = "*/2009-02-15";
 
		Consignment[] createdConsignments = service.createAndAllocateConsignmentsWithBookingCode( 
				new Consignment[] { consignment1 , consignment2 } , 
				bookingCode );
 
		for( int i = 0 ; i < createdConsignments.length ; i++ ) {
			System.out.println( "Consignment " 
					+ createdConsignments[i].getOrderNumber() 
					+ " was created with code " 
					+ createdConsignments[i].getConsignmentCode() );
		}
	}
}