Example 73 : Updating an existing consignment field
This example shows you how to update an array of fields in an existing consignment.
package com.metapack.dm.test; import com.metapack.deliverymanager.client.AllocationFilter; import com.metapack.deliverymanager.client.Consignment; import com.metapack.deliverymanager.client.UpdateField; import com.metapack.deliverymanager.client.webservices.AllocationService; import com.metapack.deliverymanager.client.webservices.ConsignmentService; public class Example73 extends ExampleBase { public void run() throws Exception { ConsignmentService service = createConsignmentService(); AllocationService allocationService = createAllocationService(); Consignment[] allocatedCons = null; Consignment updatedCons = null; //Create and allocate a consignment with 5 parcels Consignment consignment = createDefaultConsignment( "EXAMPLE-73" , 5); AllocationFilter filter = null; allocatedCons = allocationService.createAndAllocateConsignments(new Consignment[]{consignment}, filter); //String field UpdateField updateBean1 = new UpdateField(); updateBean1.setField("consignment.senderaddressline1"); updateBean1.setValue("TEST ADDRESS LINE 1"); //Date field UpdateField updateBean2 = new UpdateField(); updateBean2.setField("consignment.orderdate"); updateBean2.setValue("2010-06-30T16:51:15"); //Number field UpdateField updateBean3 = new UpdateField(); updateBean3.setField("consignment.weight"); updateBean3.setValue("3.5"); //Now let's load a warehouse (this will overwrite the sender address line 1) UpdateField updateBean4 = new UpdateField(); updateBean4.setField("consignment.sendercode"); updateBean4.setValue("Default");//is not case-sensitive //Let's load a client Account UpdateField updateBean5 = new UpdateField(); updateBean5.setField("consignment.recipientcode"); updateBean5.setValue("LocalX");//is not case-sensitive //Update parcelCount UpdateField updateBean6 = new UpdateField(); updateBean6.setField("consignment.parcelcount"); updateBean6.setValue("10"); //Update a flag UpdateField updateBean7 = new UpdateField(); updateBean7.setField("consignment.liquidgoodsflag"); updateBean7.setValue("true"); UpdateField[] updateFieldsArray = new UpdateField[7]; updateFieldsArray[0] = updateBean1; updateFieldsArray[1] = updateBean2; updateFieldsArray[2] = updateBean3; updateFieldsArray[3] = updateBean4; updateFieldsArray[4] = updateBean5; updateFieldsArray[5] = updateBean6; updateFieldsArray[6] = updateBean7; //Deallocate the consignment as the fields that we want to update required the consignment to be in unallocated status. allocationService.deallocate(new String[] {allocatedCons[0].getConsignmentCode()}); updatedCons=service.update(allocatedCons[0].getConsignmentCode(), updateFieldsArray); //Check some of the updated fields: if(updatedCons==null || updatedCons.getConsignmentWeight()!=3.5 || !updatedCons.getSenderCode().equals("Default") ){ System.out.println( "The consignment update has failed"); } } public static void main(String[] args ){ Example73 ex = new Example73(); try { ex.run(); } catch( Exception e ) { e.printStackTrace(); } } }

