AdUnitSize adUnitSize = new AdUnitSize();
adUnitSize.setSize(size);
adUnitSize.setEnvironmentType(EnvironmentType.BROWSER);
// Create a web ad unit.
AdUnit webAdUnit = new AdUnit();
webAdUnit.setName("Web_ad_unit_" + new Random().nextLong());
webAdUnit.setDescription(webAdUnit.getName());
webAdUnit.setTargetPlatform(TargetPlatform.WEB);
webAdUnit.setParentId(parentId);
webAdUnit.setTargetWindow(AdUnitTargetWindow.BLANK);
webAdUnit.setAdUnitSizes(new AdUnitSize[]{adUnitSize});
// Create a mobile ad unit.
AdUnit mobileAdUnit = new AdUnit();
mobileAdUnit.setName("Mobile_ad_unit_" + new Random().nextLong());
mobileAdUnit.setDescription(webAdUnit.getName());
mobileAdUnit.setTargetPlatform(TargetPlatform.MOBILE);
mobileAdUnit.setParentId(parentId);
mobileAdUnit.setTargetWindow(AdUnitTargetWindow.BLANK);
mobileAdUnit.setMobilePlatform(MobilePlatform.APPLICATION);
mobileAdUnit.setAdUnitSizes(new AdUnitSize[]{adUnitSize});
// Create the ad units on the server.
AdUnit[] adUnits = inventoryService.createAdUnits(new AdUnit[] {webAdUnit, mobileAdUnit});
for (AdUnit adUnit : adUnits) {