getOffers

The getOffers method enables you to request offers from the runtime server.

getOffers(String sessionID, String interactionPoint, int numberOfOffers, NameValuePair[] parameters)
  • sessionID-a string identifying the current session.

  • interactionPoint-a string identifying the name of the interaction point this method references.

    Note: This name must match the name of the interaction point defined in interactive channel exactly.
  • numberOfOffers-an integer identifying the number of offers requested.

  • parameters - NameValuePair objects identifying any parameters that are required to be passed with the API request.

The getOffers method waits the number of milliseconds defined in the segmentationMaxWaitTimeInMS property for all re-segmentation to complete before running. Therefore, if you call a postEvent method which triggers a re-segmentation or a setAudience method immediately before a getOffers call, there may be a delay.

Return value

The runtime server responds to getOffers with a Response object with the following attributes populated:

  • AdvisoryMessages
  • ApiVersion
  • OfferList
  • SessionID
  • StatusCode
  • NameValuePair

Example

This example shows requesting a single offer for the Overview Page Banner 1 interaction point and a way to handle the response.

sessionId is the same string to identify the runtime session used by the startSession call which started this session.


String interactionPoint = "Overview Page Banner 1";
int numberRequested=1;
        
/** Make the call */
response = api.getOffers(sessionId, interactionPoint, numberRequested);
       
/** Process the response appropriately */
	// check if response is successful or not
	if(response.getStatusCode() == Response.STATUS_SUCCESS)
	{
		System.out.println("getOffers call processed with no warnings or errors");
    
        /** Check to see if there are any offers */
        OfferList offerList=response.getOfferList();
            
        if(offerList.getRecommendedOffers() != null)
        {
            for(Offer offer : offerList.getRecommendedOffers())
            {
                // print offer
                System.out.println("Offer Name:"+offer.getOfferName());
            }
        }
        else // count on the default Offer String
        System.out.println("Default offer:"+offerList.getDefaultString());
    }
    else if(response.getStatusCode() == Response.STATUS_WARNING)
    {
        System.out.println("getOffers call processed with a warning");
    }
    else
    {
        System.out.println("getOffers call processed with an error");
    }
    // For any non-successes, there should be advisory messages explaining why
    if(response.getStatusCode() != Response.STATUS_SUCCESS)
        printDetailMessageOfWarningOrError("getOffers",
			response.getAdvisoryMessages());

Decimal places in offer scores are returned in the getOffer response in the NameValue Pair. When offers are returned to the requesting inbound channels, the channels use the scores to prioritize the offers. The decimal digits are not removed, and so the channel knows which offer has a higher score in case decimal numbers are returned.