Example 77 : Search for existing consignments, parcels or products
This example shows you how to use a search for consignments, parcels or products depending on the search conditions selected.
package com.metapack.dm.test; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import com.metapack.deliverymanager.client.SearchCondition; import com.metapack.deliverymanager.client.SearchOrderBy; import com.metapack.deliverymanager.client.SearchParams; import com.metapack.deliverymanager.client.SearchRecord; import com.metapack.deliverymanager.client.SearchResult; import com.metapack.deliverymanager.client.webservices.ConsignmentSearchService; /** * This example shows all of the consignments that should have been despatched * but have not yet been processed * */ public class Example77 extends ExampleBase{ public void run() throws Exception { SearchParams srchparams = new SearchParams(); String[] selectFields = {"consignment.code", "carrier.code"}; SearchOrderBy orderbyBean = new SearchOrderBy(); orderbyBean.setField("consignment.code"); orderbyBean.setDescending(false); SearchOrderBy[] orderByArr=new SearchOrderBy[1]; orderByArr[0]=orderbyBean; srchparams.setSelectFields(selectFields); srchparams.setOrderByFields(orderByArr); srchparams.setDistinct(true); Calendar cal = Calendar.getInstance(); Date cal1 =cal.getTime(); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String today = formatter.format(cal1); ConsignmentSearchService service = createConsignmentSearchService(); SearchCondition condBean = new SearchCondition("consignment.status","Ready to Manifest", "EQUALS"); SearchCondition condBean2 = new SearchCondition("consignment.EarliestDeliveryDate", today, "SMALLEROREQUALSTHAN"); SearchCondition[] condArr = new SearchCondition[2]; condArr[0]=condBean; condArr[1]=condBean2; srchparams.setConditions(condArr); srchparams.setPageNumber(1); srchparams.setPageSize(20); SearchResult result =service.search(srchparams); System.out.println( "Page count: " + result.getPageCount() + "\n total count " + result.getTotalCount()); for (int i=0;i< result.getRecords().length;i++){ SearchRecord row =result.getRecords()[i]; for(int j=0;j<row.getResult().length;j++){ System.out.println( row.getResult()[j]); } System.out.println("\n"); } System.out.println("There were " + result.getTotalCount() + " consignments matching that criteria" ); } public static void main(String[] args) { Example77 instance = new Example77(); try { instance.run(); } catch( Exception e ) { e.printStackTrace(); } } }

