DfaServices dfaServices, DfaSession session, long advertiserId,
float videoDuration, String adId, String surveyUrl,
String clickThroughUrl, long campaignId) throws Exception {
// Request the creative service from the service client factory.
CreativeRemote creativeService = dfaServices.get(session, CreativeRemote.class);
// Create the In-Stream video creative.
InStreamVideoCreative inStreamVideoCreative = new InStreamVideoCreative();
inStreamVideoCreative.setAdvertiserId(advertiserId);
inStreamVideoCreative.setName("In-Stream Video Creative #" + System.currentTimeMillis());
inStreamVideoCreative.setVideoDuration(videoDuration);
// In-Stream video creatives have to be created inactive. One can only be
// set active after at least one media file has been added to it or the API
// will return an error message.
inStreamVideoCreative.setActive(false);
// Set the video details based on the Video Ad Serving Template (VAST)
// specification.
inStreamVideoCreative.setAdId(adId);
inStreamVideoCreative.setDescription("You are viewing an In-Stream Video Creative");
inStreamVideoCreative.setSurveyUrl(surveyUrl);
inStreamVideoCreative.setClickThroughUrl(clickThroughUrl);
// Save the In-Stream video creative.
CreativeSaveResult creativeSaveResult = creativeService.saveCreative(inStreamVideoCreative,
campaignId);
// Display the new creative ID.
System.out.printf("In-Stream video creative with ID \"%s\" was created.%n",
creativeSaveResult.getId());