The PurchaseOrderManager is a sealed class and used to retrieve and store the PurchaseOrder object in Commerce Server. This class has a method named SearchPurchaseOrders() which takes two parameters to search the Purchase Orders existing in Commerce Server and returns it as a DataSet.
Parameters taken by this method:
1. SearchClause:– Specifies the conditions that a purchase order must meet in order to be included in the results of a search
2. SearchOptions:– Provides optional parameters which controls the search results performed
STEP- I (Create the instance of the OrderManagementContext using OrderServiceAgent)
The OrderManagementContext class is the root class for Orders System in Commerce Server.
It has two methods to create an OrderManagementContext instance either in Web services mode or in local mode.
Here we had used the WebService mode to create the instance of OrderManagementContext.
Example:
string orderWebServiceURL = "http://localhost/OrdersWebService/OrdersWebService.asmx"; OrderServiceAgent orderServiceAgent = new OrderServiceAgent(orderWebServiceURL); OrderManagementContext
STEP – II(Create the instance of the PurchaseOrderManager)
The PurchaseOrderManager class is also a sealed class and is used to retrieve and store the PurchaseOrder in Commerce Server.This instance can be created as follows:-
Example:
orderManagementContext = OrderManagementContext.Create(orderServiceAgent); PurchaseOrderManager
STEP-III(Create a search clause to find purchase orders whose total cost is greater than $500 US)
purchaseOrderManager = orderManagementContext.PurchaseOrderManager; DataSet searchableProperties = purchaseOrderManager.GetSearchableProperties CultureInfo.CurrentUICulture.ToString()); SearchClauseFactory searchClauseFactory = purchaseOrderManager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder"); SearchClause
STEP – IV(Specify the optional parameters to control the search results)
costClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator. GreaterThan, "Total", 500); //Create the instance of the SearchOptions class SearchOptions options = newSearchOptions(); //specify the properties you want to return by the DataSet options.PropertiesToReturn = "Created, OrderGroupId, Total, LineItemCount, OrderFormId, SoldToName, SoldToId"; //Specify the property by which the result will be sorted options.SortProperties ="Created"; //Specify the maximum number of records to return options.NumberOfRecordsToReturn = 100;
STEP – V(Get the DataSet as result by passing the parameters to the SearchPurchaseOrders() method)
DataSet
purchaseOrders = purchaseOrderManager.SearchPurchaseOrders(costClause, options); [This DataSet(purchaseOrders) contains properties informations specified in 'PropertiesToReturn' about top 100 PurchaseOrders whose Total is greater than $500 and the result is sorted by the date or the Order created]