Example 05 : Creating and allocating a consignment

Printer-friendly version

This will create a single consignment and allocate it to a carrier. By passing null as the allocation filter, the default filter is assumed. This will result in the best carrier being chosen.

If there no allocation is possible (due to, for example, excessive weight), the consignment will be left in the DM system, but in an unallocated state.

Upon a successful allocation, the consignment will be populated with all the information useful for tracking.

package com.metapack.dm.test;
 
import com.metapack.deliverymanager.client.Consignment;
import com.metapack.deliverymanager.client.webservices.AllocationService;
 
public class Example5 extends ExampleBase {
 
	public void run() throws Exception {
		AllocationService service = createAllocationService();
		Consignment consignment = createDefaultConsignment( "EXAMPLE-5" , 1 );
		Consignment[] createdConsignments = service.createAndAllocateConsignments( new Consignment[] { consignment } , null );
		Consignment createdConsignment = createdConsignments[ 0 ];
 
		if( createdConsignment.getCarrierConsignmentCode() == null ) {
			System.out.println( "The consignment could not be allocated" );
		} else {
			System.out.println( "The consignment was allocated and a given tracking code of " 
				+ createdConsignment.getCarrierConsignmentCode() );
		}
	}
}