After some research I found out that one can use the below code to do it.
$arrayofmoduleObj = JModuleHelper::getModules('position') // to get an array of module Object.
$options = array('style' => 'chrome');
foreach($arrayofmoduleObj as $moduleObject){
/* code to decide whether to print this module or not if yes */
echo JModuleHelper::renderModule($moduleObject,$options) //to render a module Object..
else continue;
}