APIを使用して、 Optimization serviceSterling Order Management System を統合する

システムインテグレーターとして、 IdleRankOptimizer APIを使用することで、 Optimization serviceSterling Order Management System を統合することができます。

始める前に

IBM® Sterling Intelligent Promising APIにアクセスするには、認証ベアラートークンを生成する必要があります。 APIトークンの生成の詳細については、 APIを使い始めるを参照してください。

Optimization serviceSterling Order Management System の間の統合ポイントであるユーザー出口をよく理解すること。 詳細については、「 システム管理コンポーネント:ユーザー終了の実装を定義する 」を参照してください。

手順

Idle API の使用

  1. アイドルAPIを開く。 詳細については、 アイドル APIを参照のこと。
  2. RESTクライアントを使用してAPIを呼び出すには、既に取得したアクセストークンを使用し、ヘッダーと入力本文と共にAPIコールを行う。 例:
    https://api.watsoncommerce.ibm.com/optimizer/{tenantId}/v1/order/idle
    ヘッダーで
    "Authorization" : "Bearer [access_token]"
  3. OMPGetExternalCostForOptionsUE ユーザー終了を使用してAPIを呼び出すには、以下のユーザー終了のサンプルを参照してください:
    package sfo.sample;
    
    import javax.xml.parsers.DocumentBuilderFactory;
    
    import org.json.JSONObject;
    import org.w3c.dom.Document;
    
    import com.mashape.unirest.http.HttpResponse;
    import com.mashape.unirest.http.Unirest;
    import com.yantra.yfs.japi.YFSEnvironment;
    import com.yantra.yfs.japi.YFSUserExitException;
    import com.yantra.yfs.japi.ue.OMPGetExternalCostForOptionsUE;
    
    public class CallSFOIdleAPI implements OMPGetExternalCostForOptionsUE 
    {
    		//replace with the OAuth URL provided for your provisioned account
    		private static final String SFO_OAUTH_URL = "https://otmz-preview.orderoptimizer.ibm.com/oauth2/endpoint/xxxxOTMZOAuthProvider/token";
    
    		//replace with the client id for your provisioned account
    		private static final String SFO_CLIENT_ID = "xxxxOTMZClient";
    		
    		//replace with the client secret for your provisioned account
    		private static final String SFO_CLIENT_SECRET = "xxxx";
    		
    		//replace with the URL for your provisioned account
    		private static final String SFO_ASYNCH_OPTIMIZATION_URL = "https://otmz-preview.orderoptimizer.ibm.com/xxxx/otmz/services/idle/V1/promiseOrder";
    		
    
    		//call out to SFO
    		/**
    		 * @param oEnv - The OMS Environment context
    		 * @param inXML - The XML representing the Promise 
    		 * @return 
    		 * @throws YFSUserExitException
    		 */
    		public Document getExternalCostForOptions(final YFSEnvironment oEnv, final Document inXML)
    				throws YFSUserExitException {
    			
    			Document outXML;
    					
    			try {
    
    				//fetch the Bearer Token
    				HttpResponse<String> authTokenResponse = Unirest.post(SFO_OAUTH_URL)
    				  .header("Content-Type", "application/x-www-form-urlencoded")
    				  .body("grant_type=client_credentials&client_id=" + SFO_CLIENT_ID + "&client_secret=" + SFO_CLIENT_SECRET)
    				  .asString();
    				String accessToken = extractToken(authTokenResponse);
    				
    				//convert XML to JSON
    				String jsonInput = convertXMLToJson(inXML);
    				
    				//populate orderDate attribute in input
    
    				//call the Optimization API
    				HttpResponse<String> optimizerApiResponse = Unirest
    						.post(SFO_ASYNCH_OPTIMIZATION_URL)
    						.header("Content-Type", "application/json").header("authorization", "Bearer " + accessToken).body(jsonInput)
    						.asString();
    				
    				outXML = convertJsonToXML(optimizerApiResponse.getBody());
    				
    				//populate attribute Overridden=N output XML
    				
    				return outXML;			
    				
    			} catch (Exception ex) {
    				ex.printStackTrace();
    				throw new YFSUserExitException("Error in calling SFO.");
    			}
    
    		}
    
    		/**
    		 * @param inXML - The XML to be converted to JSON
    		 * @return The JSON string
    		 */
    		private String convertXMLToJson(Document inXML) {
    		     String toReturn = "";
    			//convert XML to JSON String
    			return toReturn;
    
    		}
    		
    
    		/**
    		 * @param inXML - The JSON String to be converted to XML
    		 * @return The XML Document
    		 */
    
    		private Document convertJsonToXML(String string)
    				throws Exception {
    			Document outXML = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    			//convert JSON string to XML
    			return outXML;
    		}
    
    		/**
    		 * @param authTokenResponse - The HTTP Response containing the access token
    		 * @return The access token
    		 */
    		private String extractToken(HttpResponse<String> authTokenResponse) {
    			return new JSONObject(authTokenResponse.getBody()).getString("access_token");
    		}
    }
    
  4. Idle API のリクエストとレスポンスを提供する。

    Idle API は、 Sterling Order Management System からのプロミス・オーダーのリクエストを受け付ける。

Rank API の使用

  1. Rank APIを開く。 詳細は Rank APIを参照。
  2. RESTクライアントを使用してAPIを呼び出すには、既に取得したアクセストークンを使用し、ヘッダーと入力本文と共にAPIコールを行う。 例:
    https://<Base URL>/optimizer/{tenantId}/v1/order/nodes/rank
  3. 次に、以下のユーザー終了テンプレートを使用して、 IBM® Sterling Order Management System SoftwareOMPGetSourcingCorrectionsUE から Rank API を呼び出す:
    <Promise OrderHeaderKey="" OrderNo="" CarrierServiceCode="" CustomerID="" DemandType="" DistanceToConsider="" DistanceUOMToConsider="" EnterpriseCode="" IgnorePromised="" LevelOfService="" OrderReference="" OrganizationCode="" Purpose="" ReceivingNode="" SCAC="" ScacAndServiceKey="" Segment="" SegmentType="" TransactionId="" Mode="">
    	<ShipToAddress AddressLine1="" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="" Company="" Country="" DayFaxNo="" DayPhone="" Department="" EMailID="" EveningFaxNo="" EveningPhone="" FirstName="" IsCommercialAddress="" JobTitle="" LastName="" MiddleName="" MobilePhone="" OtherPhone="" PersonID="" State="" Suffix="" TaxGeoCode="" Title="" ZipCode=""/>
    	<PromiseLines TotalNumberOfRecords="">
    		<PromiseLine OrderHeaderKey="" OrderNo="" OrderLineKey="" LineId="" BundleParentLineId="" CarrierServiceCode="" DepartmentCode="" FreightTerms="" GiftWrap="" GroupID="" ItemID="" KitCode="" KitQty="" LevelOfService="" OrderLineReference="" ProductClass="" ReceivingNode="" RequiredQty="" SCAC="" ScacAndServiceKey="" Segment="" SegmentType="" UnitOfMeasure="">
    			<SourcingRuleHeader FulfillmentType="" ItemClassification="" ItemClassification2="" ItemClassification3="" ItemGroupCode="" ItemID="" NodeTypeID="" OrderSourcingClassification="" Purpose="" RegionKey="" SellerOrganizationCode="" ToNodeKey="">
    				<SourcingRuleDetails>
    					<SourcingRuleDetail DistributionRuleId="" FromNodeKey="" FutureInventoryWindow="" ProcureToShipAllowed="" SeqNo="" SubstitutionAllowed="" WorkOrderCreationAllowed="">
    						<SourcingTemplate>
    							<AdditionalData AvailableCapacityPercentage="" DaysToConsiderAvailableCapacityPercentage="" ExpandToMinimizeNumOfShipments="" ExternallyDefinedReasonCode="" IdleAsset="" Radius="" RadiusUOM=""/>
    						</SourcingTemplate>
    						<ShipNodes>
    							<ShipNode ShipNode=""/>
    						</ShipNodes>
    					</SourcingRuleDetail>
    				</SourcingRuleDetails>
    			</SourcingRuleHeader>
    			<ShipToAddress AddressLine1="" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="" Company="" Country="" DayFaxNo="" DayPhone="" Department="" EMailID="" EveningFaxNo="" EveningPhone="" FirstName="" IsCommercialAddress="" JobTitle="" LastName="" MiddleName="" MobilePhone="" OtherPhone="" PersonID="" State="" Suffix="" TaxGeoCode="" Title="" ZipCode=""/>
    			<Tag BatchNo="" LotAttribute1="" LotAttribute2="" LotAttribute3="" LotKeyReference="" LotNumber="" ManufacturingDate="" RevisionNo=""/>
    		</PromiseLine>
    	</PromiseLines>
    </Promise>

Optimizer API の使用

  1. Optimizer APIを開く。 詳細はオプティマイザー APIを参照。
    注: このオプティマイザー V2 APIは非推奨です。 新規のお客様はOptimizer V3 APIをご利用ください。
  2. RESTクライアントを使用してAPIを呼び出すには、既に取得したアクセストークンを使用し、ヘッダーと入力本文と共にAPIコールを行う。 例:

https://<BaseURL>/optimizer/{tenantId}/v3/order/optimization

  1. 次に、以下のユーザー終了テンプレートを使用して、 IBM Sterling Order Management System SoftwareOMPGetExternalCostForOptionsUE から Optimizer API を呼び出す:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Licensed Materials - Property of IBM
    IBM Sterling Selling and Fulfillment Suite, Sterling Order Management
    System (5737-D18)
    (C) Copyright IBM Corp. 2010, 2020 All Rights Reserved.
    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
     -->
    <Promise>
        <PromiseLines>
            <PromiseLine CarrierServiceCode="" DeliveryMethod=""
                DistributionRuleId="" FillQuantity="" FulfillmentType=""
                ItemID="" LineId="" OrderLineReference="" ProductClass=""
                ReceivingNode="" RequiredQty="" SCAC="" ScacAndServiceKey=""
                ShipNode="" UnitOfMeasure="">
                <ShipToAddress  Country="" State="" ZipCode="" PersonInfoKey="" />
                <PossibleAssignments>
                    <Assignment AssignmentKey="" Capacity=""
                        CapacityConsumed="" CapacityUnitOfMeasure=""
                        CapacityUtilization="" CarrierServiceCode=""
                        DeliveryDate="" Distance="" NodeProcessingDate=""
                        ProcuredQty="" ProductAvailDate="" Quantity=""
                        SCAC="" ShipDate="" ShipNode="">
                        <PossibleCarriers>
                            <Carrier CarrierServiceCode=""
                                ExpectedDeliveryDate="" ExpectedShipmentDate=""/>
                        </PossibleCarriers>
                        <Supplies>
                            <Supply AvailableQuantity="" FirstShipDate=""
                                LastShipDate="" SafetyQuantity="" Track=""/>
                        </Supplies>
                        <Costs Currency="" HoursOfSupplyCostPerUnit=""
                            ItemInventoryCostPerUnit=""
                            NodePriorityCostPerUnit=""
                            NodeShippingCapacityCostPerUnit=""
                            OutboundShipmentHandlingCostPerUnit="" ShipmentDelayCostPerUnit=""/>
                        <SubstituteItems>
                            <SubstituteItem AssignmentKey="" Capacity=""
                                CapacityConsumed="" CapacityUnitOfMeasure=""
                                CapacityUtilization="" ItemID=""
                                ProcuredQty="" ProductClass="" Quantity=""
                                ShipDate="" UOM="">
                                <Costs Currency="" ItemInventoryCostPerUnit=""/>
                                <Supplies>
                                    <Supply AvailableQuantity=""
                                        FirstShipDate="" LastShipDate=""
                                        SafetyQuantity="" Track=""/>
                                </Supplies>
                                <Procurements>
                                    <Procurement AssignmentKey=""
                                        Capacity="" CapacityConsumed=""
                                        CapacityUnitOfMeasure=""
                                        CapacityUtilization=""
                                        ProcureFromNode="" Quantity="" ShipDate="">
                                        <Costs Currency=""
                                        ItemInventoryCostPerUnit=""
                                        NodePriorityCostPerUnit=""
                                        NodeShippingCapacityCostPerUnit="" OutboundShipmentHandlingCostPerUnit=""/>
                                        <Supplies>
                                        <Supply AvailableQuantity=""
                                        FirstShipDate=""
                                        LastShipDate=""
                                        SafetyQuantity="" Track=""/>
                                        </Supplies>
                                    </Procurement>
                                </Procurements>
                            </SubstituteItem>
                        </SubstituteItems>
                        <Procurements>
                            <Procurement AssignmentKey="" Capacity=""
                                CapacityConsumed="" CapacityUnitOfMeasure=""
                                CapacityUtilization="" ProcureFromNode=""
                                Quantity="" ShipDate="">
                                <Costs Currency=""
                                    ItemInventoryCostPerUnit=""
                                    NodePriorityCostPerUnit=""
                                    NodeShippingCapacityCostPerUnit="" OutboundShipmentHandlingCostPerUnit=""/>
                                <Supplies>
                                    <Supply AvailableQuantity=""
                                        FirstShipDate="" LastShipDate=""
                                        SafetyQuantity="" Track=""/>
                                </Supplies>
                            </Procurement>
                        </Procurements>
                    </Assignment>
                </PossibleAssignments>
            </PromiseLine>
        </PromiseLines>
        <SuggestedOption>
            <Option AvailableFromUnplannedInventory="" FirstDate=""
                HasAnyUnavailableQty="" LastDate="" LeastPriority=""
                MaxPriority="" NodeQty="" TotalShipments="">
                <PromiseLines TotalNumberOfRecords="">
                    <PromiseLine CarrierServiceCode="" DeliveryMethod=""
                        ItemID="" LineId="" ProductClass="" RequiredQty="" UnitOfMeasure="">
                        <Assignments TotalNumberOfRecords="">
                            <Assignment DeliveryDate="" Distance=""
                                EmptyAssignmentReason="" InteractionNo=""
                                InvQty="Required" IsReservationOnly=""
                                MergeNode="" NodePriority=""
                                NodeProcessingDate="" ProcuredQty=""
                                ProductAvailDate="" Quantity=""
                                QuantityFromUnplannedInventory=""
                                ReservedQty="" SCAC="" SegmentChangeQty=""
                                ShipDate="" ShipNode="" SubstitutedQty="" TransferNo="">
                                <SubstituteItems>
                                    <SubstituteItem ItemID="" ProcuredQty=""
                                        ProductClass="" Quantity=""
                                        ReservedQty="" UOM="">
                                        <Procurements>
                                        <Procurement ProcureFromNode=""
                                        Quantity="" ShipDate="" TransferNo=""/>
                                        </Procurements>
                                    </SubstituteItem>
                                </SubstituteItems>
                                <Procurements>
                                    <Procurement ProcureFromNode=""
                                        ProductAvailDate="" Quantity=""
                                        ShipDate="" TransferNo=""/>
                                </Procurements>
                            </Assignment>
                        </Assignments>
                    </PromiseLine>
                </PromiseLines>
                <Interactions TotalNumberOfRecords="">
                    <Interaction ApptEndTimestamp="" ApptStartTimestamp=""
                        Carrier="" CarrierServiceCode="" DeliveryDate=""
                        DeliveryMethod="" InteractionNo="" IsDelivery=""
                        ItemGroupCode="" LevelOfService="" Node=""
                        OrganizationCode="" ShipDate="">
                        <PersonInfoShipTo AddressLine1="" AddressLine2=""
                            AddressLine3="" AddressLine4="" AddressLine5=""
                            AddressLine6="" AlternateEmailID="" Beeper=""
                            City="" Company="" Country="" DayFaxNo=""
                            DayPhone="" Department="" EMailID="" ErrorTxt=""
                            EveningFaxNo="" EveningPhone="" FirstName=""
                            HttpUrl="" IsAddressVerified=""
                            IsCommercialAddress="" JobTitle="" LastName=""
                            Latitude="" Longitude="" MiddleName=""
                            MobilePhone="" OtherPhone="" PersonID=""
                            PreferredShipAddress="" State="" Suffix=""
                            TaxGeoCode="" Title="" UseCount=""
                            VerificationStatus="" ZipCode="" isHistory=""/>
                    </Interaction>
                </Interactions>
                <Costs Currency="" HandlingCost="" HoursOfSupplyCost=""
                    ItemInventoryCost="" NodePriorityCost=""
                    NodeShippingCapacityCost="" ShipmentDelayCost=""
                    TotalCost="" TransportationCost=""/>
            </Option>
        </SuggestedOption>
    </Promise>
  2. Optimizer V2 API のリクエストとレスポンスを提供する。 例:
    <Promise OrderDate="" OrderNo="">
      <PromiseLines>
    
        <PromiseLine CarrierServiceCode="" ItemID="" LineId="" ProductClass="" RequiredQty="" UnitOfMeasure=""  DeliveryMethod="" IsPreDefinedNode="">
           <ShipToAddress Country="" State="" ZipCode="" />
          <PossibleAssignments>
             <Assignment AssignmentKey="" CapacityConsumed="" CapacityUtilization="" Distance="" Quantity=""  ShipNode="" IsExternalNode="" DeliveryDate="" ShipDate="">
                <Supplies>
                 <Supply AvailableQuantity="" FirstShipDate="" LastShipDate="" SafetyQuantity="" Track="" /> 
    </Supplies>
             </Assignment>
          </PossibleAssignments>
        </PromiseLine>
      </PromiseLines>
      <SuggestedOption>
        <Option FirstDate="" HasAnyUnavailableQty="" LastDate="" TotalShipments="">
          <PromiseLines>
             <PromiseLine LineId="">
                <Assignments>
                 <Assignment DeliveryDate="" Distance="" EmptyAssignmentReason="" InteractionNo="" Quantity=""  ShipDate="" ShipNode="" /> </Assignments>
             </PromiseLine>
          </PromiseLines>
          <Interactions>
             <Interaction Carrier="" CarrierServiceCode="" DeliveryDate="" DeliveryMethod="" InteractionNo="" Node="" ShipDate="">
               <PersonInfoShipTo Country="" State="" ZipCode="" /> </Interaction>
          </Interactions>
        </Option>
      </SuggestedOption>
    </Promise>
    The Optimizer API response is returned in XML format.
    
    <Promise OrderNo="" OrderDate="">
      <PromiseLines>
       <PromiseLine LineId="" ItemID="">
         <PossibleAssignments>
          <Assignment AssignmentKey="" Quantity="" IsExternalNode="" RejectChoice="" RejectionReason=""  FirstShipDate="">
            <PossibleCarriers>
              <Carrier CarrierServiceCode="" Scac="" ExpectedShipDate=""></Carrier>
            </PossibleCarriers>
            <Costs AssignmentPriority=""></Costs>
          </Assignment>
        </PossibleAssignments>
       </PromiseLine>
      </PromiseLines>
    </Promise>
    

    CapacityConsumed 属性は、フルフィルメント・ネットワーク・ロードバランシング・コストのコンフィギュレーションが0より大きく設定されている場合に必要となる。 それ以外の場合はオプションです。 Idle API は、 Sterling Order Management System からのプロミス・オーダーのリクエストを受け付ける。