Entity requirement = new Entity("msdyn_resourcerequirement");
requirement["msdyn_fromdate"] = bookingDate;
requirement["msdyn_todate"] = bookingDate.Add(TimeSpan.FromMinutes(Convert.ToDouble(estimatedDuration)));
requirement["msdyn_effort"] = 1;
requirement["msdyn_remainingduration"] = estimatedDuration;
EntityCollection characterstics = new EntityCollection();
characterstics.Entities.Add(new Entity("characteristic", preferredSkill.Id));
EntityCollection category = new EntityCollection();
category.Entities.Add(new Entity("bookableresourcecategory", preferredRole.Id));
EntityCollection orgUnit = new EntityCollection();
orgUnit.Entities.Add(new Entity("msdyn_organizationalunit", preferredOrganizationalUnit.Id));
Entity resourcespecification = new Entity("organization");
Entity constraints = new Entity("organization");
constraints["Characteristics"] = characterstics;
constraints["Roles"] = category;
resourcespecification["Constraints"] = constraints;
Entity settings = new Entity("organization");
settings.Attributes.Add("ConsiderSlotsWithProposedBookings", true);
settings.Attributes.Add("ConsiderSlotsWithLessThanRequiredCapacity", false);
OrganizationRequest reqAction = new OrganizationRequest("msdyn_SearchResourceAvailability");
reqAction["Version"] = "1";
reqAction["Requirement"] = requirement;
reqAction["Settings"] = settings;
reqAction["ResourceSpecification"] = resourcespecification;
//execute the request
OrganizationResponse response = service.Execute(reqAction);