Iterate through the timedMetadataList and find the CAID

You need to iterate through the timedMetadataList to find and return the CAID (airing ID) associated with the provided local time.

  1. Step through the timedMetadataList:
    private String getAiringIdForTime(long time, List<TimedMetadata> timedMetadataList) {
    
    	for (TimedMetadata timedMetadata : timedMetadataList) {
    		if (timedMetadata.getTime() == time
    			&& timedMetadata.getMetadata() != null
    			&& timedMetadata.getMetadata().containsKey(OPPORTUNITY_ID_KEY)) {
    		return timedMetadata.getMetadata().getValue(OPPORTUNITY_ID_KEY);
    		}
    	}
    	return null;
    }
  2. Then, add the following code:
    private PlacementOpportunity createPlacementOpportunity(TimedMetadata timedMetadata, String
     airingId, Metadata metadata) {
    	long time = timedMetadata.getTime();
    	long duration = 0;
    
    	Metadata rawMetadata = timedMetadata.getMetadata();
    	if (rawMetadata.containsKey(OPPORTUNITY_DURATION_KEY)) {
    	 duration = NumberUtils.parseNumber(rawMetadata.getValue(OPPORTUNITY_DURATION_KEY),0) * 1000;
    	}
    
    	if (duration <= 0) {
    	return null;
    	}
    
    	// The custom params to be sent to the ad provider.
    	MetadataNode customParams = new MetadataNode();
    	customParams.setValue(PSDK_AVAIL_DURATION_KEY, String.valueOf(duration/1000));
    	customParams.setValue(PSDK_ASSET_ID_KEY, String.valueOf(getAiringIdAsLong(airingId)));
    	((MetadataNode) metadata).setNode(DefaultMetadataKeys.CUSTOM_PARAMETERS.getValue(), customParams);
    
    	return new PlacementOpportunity(
    		String.valueOf(timedMetadata.getId()),
    		new PlacementInformation(Type.MID_ROLL, time, duration), metadata
    	);
    }